package com.fengye.algorithms.leecode;

/**
 * @Author fengye
 * @Date 2023/4/10 9:50
 **/
public class AreAlmostEqual1790 {
    public boolean areAlmostEqual(String s1, String s2) {
        if(s1.length() != s2.length()) {
            return false;
        }

        if(s1.equals(s2)) {
            return true;
        }
        char[] s1c = new char[2];
        char[] s2c = new char[2];
        int diff = 0;
        for(int i = 0; i < s1.length();i++) {
            if(s1.charAt(i) != s2.charAt(i)){
                diff++;
                if(diff <= 2) {
                    s1c[diff-1] = s1.charAt(i);
                    s2c[diff-1] = s2.charAt(i);
                }
            }

            if(diff > 2) {
                return false;
            }
        }

        return s1c[0] == s2c[1] && s1c[1] == s2c[0];
    }
}
